//
//  UIButton+Tap.m
//  SSL_Runtime_Learn
//
//  Created by SSLong on 2018/2/11.
//  Copyright © 2018年 sunshilong. All rights reserved.
//

#import "UIButton+Tap.h"
#import <objc/runtime.h>

static const void *associatedKey = "associatedKey";
@implementation UIButton (Tap)


- (void)setTapButton:(Tap_button)tapButton{
    objc_setAssociatedObject(self, associatedKey, tapButton, OBJC_ASSOCIATION_COPY_NONATOMIC);
    
    [self removeTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
    if (tapButton) {
        [self addTarget:self action:@selector(buttonTap:) forControlEvents:UIControlEventTouchUpInside];
    }
}
- (Tap_button)tapButton{
    return objc_getAssociatedObject(self, associatedKey);
}
- (void)buttonTap:(UIButton*)sender{
    if (self.tapButton) {
        self.tapButton();
    }
}
@end
